package com.appkubes.mall.restful.fintech.user.baseInfo.service.impl;

import com.appkubes.mall.core.po.FintechUserBaseInfo;
import com.appkubes.mall.restful.fintech.user.baseInfo.dao.UserBaseInfoDao;
import com.appkubes.mall.restful.fintech.user.baseInfo.entity.vo.UserBaseInfoVO;
import com.appkubes.mall.restful.fintech.user.baseInfo.service.UserBaseInfoService;
import com.appkubes.mall.restful.fintech.user.basic.entity.vo.FintechUserVO;
import com.appkubes.mall.restful.fintech.user.basic.service.FintechUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class UserBaseInfoServiceImpl implements UserBaseInfoService {

    @Resource
    UserBaseInfoDao userBaseInfoDao;

    @Resource
    FintechUserService fintechUserService;

    @Override
    public int register(UserBaseInfoVO userBaseInfoVO) {
        com.appkubes.mall.core.po.FintechUserBaseInfo fintechUserBaseInfo = new com.appkubes.mall.core.po.FintechUserBaseInfo();
        BeanUtils.copyProperties(userBaseInfoVO, fintechUserBaseInfo);

        fintechUserBaseInfo.setCreateTime(new Date());
        fintechUserBaseInfo.setUpdateTime(new Date());
        int flag = userBaseInfoDao.insertSelective(fintechUserBaseInfo);

        if (flag > 0) {
            //注册用户信息
            FintechUserVO fintechUserVO = new FintechUserVO();
            fintechUserVO.setUserKey(userBaseInfoVO.getUserKey());
            flag = fintechUserService.register(fintechUserVO);
        }

        return flag;
    }

    @Override
    public FintechUserBaseInfo getById(String userKey) {
        return userBaseInfoDao.selectByPrimaryKey(userKey);
    }
}
